package cn.stylefeng.guns.sys.modular.tao.controller;

import cn.stylefeng.guns.sys.modular.api.sdk.Utils;
import cn.stylefeng.guns.sys.modular.tao.service.MemberService;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    private Gson gson;

    @Autowired
    MemberService memberService;

    /**
     *
     * 查询会员
     * @param id
     * @return
     */
    public String getMember(Long id){
        if (Utils.checkStringIsNull(id.toString())) {
            ResponseData dataMsg = new ResponseData();
            dataMsg.setMessage("参数不能为空");
            dataMsg.setCode(500);
            return gson.toJson(dataMsg);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        ResponseData data = memberService.getMember(map);

        return gson.toJson(data);
    }

    /**
     *
     * 添加会员
     * @param id
     * @return
     */
    public String addMember(Long id,String commission,String purchaseQuota){
        if (Utils.checkStringIsNull(id.toString())) {
            ResponseData dataMsg = new ResponseData();
            dataMsg.setMessage("参数不能为空");
            dataMsg.setCode(500);
            return gson.toJson(dataMsg);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("commission", commission);
        map.put("purchaseQuota", purchaseQuota);
        ResponseData data = memberService.addMember(map);

        return gson.toJson(data);
    }


    /**
     *
     * 修改会员信息
     * @param id
     * @return
     */
    public String editMember(Long id,String delSign,String commission,String purchaseQuota,String integral){
        if (Utils.checkStringIsNull(id.toString())) {
            ResponseData dataMsg = new ResponseData();
            dataMsg.setMessage("参数不能为空");
            dataMsg.setCode(500);
            return gson.toJson(dataMsg);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("integral", integral);
        map.put("commission", commission);
        map.put("purchaseQuota", purchaseQuota);
        map.put("delSign", delSign);
        ResponseData data = memberService.editMember(map);

        return gson.toJson(data);
    }

    /**
     * 会员过期
     */
    public String deleteMemberInfo(Long id){
        if (Utils.checkStringIsNull(id.toString())) {
            ResponseData dataMsg = new ResponseData();
            dataMsg.setMessage("参数不能为空");
            dataMsg.setCode(500);
            return gson.toJson(dataMsg);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        ResponseData data = memberService.deleteMemberInfo(map);

        return gson.toJson(data);
    }

}
